﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using ICSharpCode;


namespace SeCompUFSCarWeb.PDF
{
    public static class PDF
    {
        public static bool GerarPDF(string saveAsPath, string certificadoPath, string name, string id)
        {
            Stream stream = new FileStream(saveAsPath + id + ".pdf", FileMode.OpenOrCreate);
            Document pdfDocument = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);

            try
            {
                PdfWriter.getInstance(pdfDocument, stream);
                pdfDocument.Open();

                BaseFont helvetica = BaseFont.createFont("Helvetica", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                Color cor = new Color(64, 64, 154);
                Font fonte = new Font(helvetica, 34, Font.NORMAL, cor);

                Chunk texto = new Chunk(name, fonte);
                Paragraph paragrafo = new Paragraph(215, texto);
                paragrafo.Alignment = Element.ALIGN_CENTER;
                
                
                Image certificado = Image.getInstance(certificadoPath);
                certificado.Alignment = Image.UNDERLYING;
                certificado.scaleToFit(842, 595);


                pdfDocument.Add(certificado);
                pdfDocument.Add(paragrafo);

                

            }
            catch (Exception)
            {

            }
            finally
            {
                pdfDocument.Close();
            }
            
            return false;
        }
    }
}